/**
 * 
 */

package com.chengyu.eyc.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.chengyu.eyc.base.ResponseResult;
import com.chengyu.eyc.queue.RabbitMQConfig;

/**
 * @author kevin
 *
 */
@RequestMapping("msg")
@RestController
public class MessageController extends AbstractBaseController {

    @Autowired
    RabbitTemplate rabbitTemplate; // 使用RabbitTemplate,这提供了接收/发送等等方法

    @GetMapping("/sendMessage")
    public ResponseResult<String> sendDirectMessage(@RequestParam String message) {
        /**
         * 发送消息 参数一：交换机名称 参数二：路由key: item.springboot-rabbitmq,符合路由item.#规则即可 参数三：发送的消息
         */
        rabbitTemplate.convertAndSend(RabbitMQConfig.MESSAGE_TOPIC_EXCHANGE, "message.001", message);
        return ResponseResult.ok();
    }

}
